<template>
	<view class="arrears-pages">
		<view class="info-content">
			<view class="menu-item">
				<view class="menu" :class="menuTab==1?'active':''" @click="changMenu(1)">全部</view>
				<view class="menu" :class="menuTab==2?'active':''" @click="changMenu(2)">房租</view>
				<view class="menu" :class="menuTab==3?'active':''" @click="changMenu(3)">物业</view>
				<view class="menu" :class="menuTab==4?'active':''" @click="changMenu(4)">保证金</view>
			</view>
			<view class="search-block">
				<input placeholder="请输入关键字" v-model="keyword" class="search" />
				<view class="small-btn normal">搜索</view>
			</view>
		</view>
		<checkbox-group class="info-block" @change="checkboxChange">
			<view class="info-item" v-for="item in list" :key="item.id">
				<checkbox :value="item.id" :checked="form.checktId.some(data=>Number(data)===item.id)"
					style="transform:scale(0.7);" class="checkbox" color="#fb4744" />
				<view class="arrears-block">
					<view class="rent-info">
						<image :src="imgStorage+'/login/lianzu.png'" class="info-icon" v-if="item.type==1"></image>
						<image :src="imgStorage+'/login/gongzu.png'" class="info-icon" v-else-if="item.type==2"></image>
						<image :src="imgStorage+'/login/zhiguan.png'" class="info-icon" v-else-if="item.type==3">
						</image>
						<view class="title">{{item.name}}</view>
					</view>
					<view class="rent-item">
						<view class="rent-itme">{{item.title}}</view>
						<view class="form-info">
							<view class="form-content">-{{item.price}}元</view>
							<view class="iconfont icon-a-jinggao1"
								@click="navigate('/page_pack/rent_payment/rent_calculator')">
							</view>
						</view>
					</view>
					<view class="time">缴费时间：{{item.rentTime}}</view>
				</view>
			</view>
		</checkbox-group>
		<view class="bottom-block">
			<view class="bottom-info">
				<checkbox-group @change="allCheckEvent">
					<checkbox :checked="allIds.length==form.checktId.length" style="transform:scale(0.7);"
						color="#fb4744" />
				</checkbox-group>
				<view class="title">全选</view>
				<view class="select-item">
					<view class="text">已选{{form.checktId.length}}项</view>
					<view class="price-item">
						<view class="price-name">总金额</view>
						<view class="price">￥{{totalPrice}}</view>
					</view>
				</view>
			</view>
			<view class="small-btn normal" @click="submit">发票申请</view>
		</view>
	</view>
</template>

<script>
	import {
		SelectHouse
	} from '@/components/SelectHouse.vue'
	import {
		getStorage
	} from '@/util/auth.js';
	import {
		validate
	} from '@/util/validate.js';
	export default {
		components: {
			SelectHouse
		},
		data() {
			return {
				keyword: '',
				menuTab: 1,
				selectInfo: {},
				totalPrice: 0,
				allIds: [],
				list: [{
						id: 1,
						type: 1,
						name: '北片世博花园12#4-401',
						title: '2025年房租缴纳',
						price: '775.20',
						rentTime: '2025-02-25 18：24',
					},
					{
						id: 2,
						type: 1,
						name: '北片世博花园12#4-402',
						title: '2024年7-12月欠费房租补缴',
						price: '387.6',
						rentTime: '2025-02-25 18：24',
					},
					{
						id: 3,
						type: 2,
						name: '北片世博花园10#3-401',
						title: '滞纳金',
						price: '61.3',
						rentTime: '2025-02-25 18：24',
					}
				],
				form: {
					checktId: [],
				},
				rule: {
					checktId: {
						name: '',
						required: false,
						validator: function(value, form, callback) {
							if (value.length == 0) {
								callback('请选择需开票项目！');
							}
							callback();
						}
					},
				}
			}
		},
		methods: {
			changMenu(e) {
				this.menuTab = e
			},
			checkboxChange(e) {
				this.totalPrice = 0
				this.form.checktId = e.detail.value
				let fillereArray = this.list.filter(item => this.form.checktId.includes(String(item.id)))
				fillereArray.forEach(item => {
					this.totalPrice += Number(item.price)
					this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
				})
			},
			allCheckEvent(e) {
				this.totalPrice = 0
				if (e.detail.value.length > 0) {
					this.form.checktId = this.allIds
					let fillereArray = this.list.filter(item => this.allIds.includes(item.id))
					fillereArray.forEach(item => {
						this.totalPrice += Number(item.price)
						this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
					})
				} else {
					this.form.checktId = []
					this.totalPrice = 0
				}
			},
			submit() {
				if (validate(this.form, this.rule)) {
					this.navigate('/page_pack/invoice/info?price=' + this.totalPrice)
				}
			}
		},
		onLoad() {
			this.list.forEach(item => {
				this.allIds.push(item.id)
			})
		},
		onShow() {
			this.selectInfo = getStorage('selectInfo')
		}
	}
</script>
<style lang="scss" scoped>
	.arrears-pages {
		.info-content {
			padding: 30rpx 30rpx 0 30rpx;

			.menu-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 30rpx;

				.menu.active {
					background-color: $theme-color;
					color: #fff;
				}

				.menu {
					width: calc(25% - 15rpx);
					height: 65rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					background-color: #fff;
					border-radius: 10rpx;
					font-size: 30rpx;
					color: #767676;
				}
			}

			.search-block {
				background-color: #fff;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-radius: 60rpx;
				padding: 0 20rpx;

				.small-btn {
					width: 140rpx;
				}
			}
		}

		.info-block {
			padding: 30rpx;
			padding-bottom: 180rpx;

			.info-item {
				padding: 30rpx;
				background-color: #fff;
				border-radius: 30rpx;
				margin-bottom: 30rpx;
				display: flex;
				align-items: flex-start;
				justify-content: space-between;

				.checkbox {}

				.arrears-block {
					width: calc(100% - 60rpx);

					.rent-info {
						display: flex;
						align-items: center;
						border-bottom: 1px solid #eeeeee;
						padding-bottom: 30rpx;
						margin-bottom: 30rpx;

						.info-icon {
							width: 40rpx;
							height: 40rpx;
							margin-right: 10rpx;
						}

						.title {
							width: calc(100% - 50rpx);
							font-size: 30rpx;
							font-weight: bold;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}

					.time {
						font-size: 28rpx;
						color: #767676;
					}

					.rent-item {
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-bottom: 20rpx;

						.rent-itme {
							font-size: 30rpx;
							width: 65%;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;

						}

						.form-info {
							display: flex;
							align-items: center;

							.form-content {
								font-size: 30rpx;
								font-weight: bold;
								margin-right: 10rpx;
							}
						}
					}
				}
			}
		}

		.bottom-block {
			background-color: #fff;
			position: fixed;
			bottom: 0;
			height: 170rpx;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx;

			.bottom-info {
				display: flex;
				align-items: center;

				.title {
					font-size: 30rpx;
					margin-right: 30rpx;
				}

				.select-item {
					.text {
						font-size: 26rpx;
						color: #767676;
						margin-bottom: 10rpx;
					}

					.price-item {
						display: flex;
						align-items: center;

						.price-name {
							font-size: 28rpx;
						}

						.price {
							font-size: 40rpx;
							color: $theme-color;
						}
					}
				}
			}

			.small-btn {
				width: 200rpx;
				height: 80rpx;
			}
		}
	}
</style>